import db, datetime
#~ from urllib import urlopen
#~ from BeautifulSoup import BeautifulSoup

import os
CONFIG_FILE = os.path.join(os.environ['HOME'], '.wjs.ini')
try:
	from ConfigParser import SafeConfigParser as ConfigParser
except ImportError:
	from ConfigParser import ConfigParser

config = ConfigParser()
config.read(CONFIG_FILE)

db.init(config.get("dsn", "games"))

for line in open("games.txt", "r"):
	name, platform, date = line[:-1].split(",")
	platform = db.getPlatform(platform)

	try:
		date = datetime.datetime.strptime(date, "%d %b %Y")
	except ValueError:
		date = None

	try:
		db.Game(name = name, platform = platform, releaseDate = date)
	except db.dberrors.DuplicateEntryError:
		if date:
			db.Game.byName(name).set(releaseDate = date)


